package cn.com.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.com.biz.KeShiBiz;
import cn.com.entity.KeShi;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class KeShiAction extends ActionSupport implements Action,SessionAware{
	Map<String, Object> session;
	
	public Map<String, Object> getSession() {
		return session;
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		session=arg0;
		
	}
	private int keshiid;
	private String keshiming;
	private KeShiBiz keshiBiz;
	

	public KeShiBiz getKeshiBiz() {
		return keshiBiz;
	}

	public void setKeshiBiz(KeShiBiz keshiBiz) {
		this.keshiBiz = keshiBiz;
	}

	public int getKeshiid() {
		return keshiid;
	}

	public void setKeshiid(int keshiid) {
		this.keshiid = keshiid;
	}

	public String getKeshiming() {
		return keshiming;
	}

	public void setKeshiming(String keshiming) {
		this.keshiming = keshiming;
	}
	public String chakankeshi(){
		ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
		keshiBiz=(KeShiBiz)ctx.getBean("keshiBiz");
		List<KeShi> cklist=keshiBiz.chakankeshi();
		if(cklist!=null){
			session.put("cklist", cklist);
			return SUCCESS;
		}else{
			return ERROR;
		}
	}
	public String insertkeshi(){
		boolean b=keshiBiz.insertkeshi(keshiid, keshiming);
		if(b){
			return "tianjiachenggong";
		}else{
			return "tianjiashibai";
		}
	}
	public String deletekeshi(){
		boolean b=keshiBiz.deletekeshi(keshiid);
		if(b){
			return "shanchuchenggong";
		}else{
			return "shanchushibai";
		}
	}
	public String updatekeshi(){
		boolean b=keshiBiz.updatekeshi(keshiid, keshiming);
		if(b){
			return "xiugaichenggong";
		}else{
			return "xiugaishibai";
		}
	}
}
